package com.dc.toolkit.hutool.crypto;

import cn.hutool.crypto.SecureUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Description: Hutool SecureUtil Demo
 * @author: gdc
 * @date: 2021/5/9
 * @version 1.0
 */
public class SecureUtilTest {

    String CONTENT = "测试加密的数据";

    /**
     * 测试   MD5 加密，加密后的长度为                  32位
     */
    @Test
    public void testMd5(){
        String md5Str = SecureUtil.md5(CONTENT);
        assertThat(md5Str, equalTo("a483e744988e6610f0a4781893129110"));
        System.out.println(md5Str);
    }

    /**
     * 测试   SHA1加密，生成16进制SHA1字符串            40位
     */
    @Test
    public void testSha1(){
        String sha1Str = SecureUtil.sha1(CONTENT);
        assertThat(sha1Str, equalTo("e53fabcaa128a898183462f27b8d0c79e0e3cdc0"));
        System.out.println(sha1Str);
    }

    /**
     * 测试   SHA256加密，生成16进制SHA256字符串        64位
     *
     */
    @Test
    public void testSha256(){
        String sha256Str = SecureUtil.sha256(CONTENT);
        assertThat(sha256Str, equalTo("c2bab900cccad6ba37065d67062b96729ed5969f6123b2680a86ef86c10f487d"));
        System.out.println(sha256Str);
    }

}
